package edu.usx.server.controller;


import edu.usx.server.pojo.RespBean;
import edu.usx.server.pojo.dto.CategoryDto;
import edu.usx.server.pojo.dto.EditRoleDto;
import edu.usx.server.service.IAdminService;
import edu.usx.server.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Usx
 * @since 2024-07-18
 */
@Slf4j
@RestController
@RequestMapping("/admin")
@Api(value = "AdminController")
public class AdminController {
    @Resource
   private IAdminService adminService;
    @Autowired
    private ICategoryService categoryService;


    @PutMapping("/editrole")
    public RespBean editRole (@RequestBody EditRoleDto editRoleDto) {
        return adminService.editRole(editRoleDto.getId(),editRoleDto.getRoleId());
    }


    /**
     * 管理员新增分类数据
     * @param categoryDto
     * @return
     */
    @PostMapping("/category")
    @ApiOperation("新增分类数据")
    public RespBean addCategory(@RequestBody CategoryDto categoryDto){
        log.info("新增分类数据");

        return categoryService.addcategoryWithcid(categoryDto);
    }

    /**
     * 根据id修改分类数据
     */
    @PutMapping("/category")
    @ApiOperation("修改分类数据")
    public RespBean update(@RequestBody CategoryDto categoryDto){
        log.info("新增分类数据");
        return categoryService.updateWithcid(categoryDto);
    }
    /**
     * 根据id删除分类数据
     */
    @DeleteMapping("/category")
    @ApiOperation("根据id删除分类")
    public  RespBean delete( Integer id){
        log.info("根据id删除分类");
        return categoryService.deleteWithcid(id);
    }

}
